home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / test / test_shutil.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  4KB  |  115 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.4)
  3.  
  4. import unittest
  5. import shutil
  6. import tempfile
  7. import sys
  8. import stat
  9. import os
  10. import os.path as os
  11. from test import test_support
  12. from test.test_support import TESTFN
  13.  
  14. class TestShutil(unittest.TestCase):
  15.     
  16.     def test_rmtree_errors(self):
  17.         filename = tempfile.mktemp()
  18.         self.assertRaises(OSError, shutil.rmtree, filename)
  19.  
  20.     if hasattr(os, 'chmod') and sys.platform[:6] != 'cygwin':
  21.         if hasattr(os, 'geteuid'):
  22.             pass
  23.         if not (os.geteuid() == 0):
  24.             
  25.             def test_on_error(self):
  26.                 self.errorState = 0
  27.                 os.mkdir(TESTFN)
  28.                 self.childpath = os.path.join(TESTFN, 'a')
  29.                 f = open(self.childpath, 'w')
  30.                 f.close()
  31.                 old_dir_mode = os.stat(TESTFN).st_mode
  32.                 old_child_mode = os.stat(self.childpath).st_mode
  33.                 os.chmod(self.childpath, stat.S_IREAD)
  34.                 os.chmod(TESTFN, stat.S_IREAD)
  35.                 shutil.rmtree(TESTFN, onerror = self.check_args_to_onerror)
  36.                 self.assertEqual(self.errorState, 2)
  37.                 os.chmod(TESTFN, old_dir_mode)
  38.                 os.chmod(self.childpath, old_child_mode)
  39.                 shutil.rmtree(TESTFN)
  40.  
  41.         
  42.     
  43.     def check_args_to_onerror(self, func, arg, exc):
  44.         if self.errorState == 0:
  45.             self.assertEqual(func, os.remove)
  46.             self.assertEqual(arg, self.childpath)
  47.             self.assertEqual(exc[0], OSError)
  48.             self.errorState = 1
  49.         else:
  50.             self.assertEqual(func, os.rmdir)
  51.             self.assertEqual(arg, TESTFN)
  52.             self.assertEqual(exc[0], OSError)
  53.             self.errorState = 2
  54.  
  55.     
  56.     def test_rmtree_dont_delete_file(self):
  57.         (handle, path) = tempfile.mkstemp()
  58.         os.fdopen(handle).close()
  59.         self.assertRaises(OSError, shutil.rmtree, path)
  60.         os.remove(path)
  61.  
  62.     
  63.     def test_dont_move_dir_in_itself(self):
  64.         src_dir = tempfile.mkdtemp()
  65.         
  66.         try:
  67.             dst = os.path.join(src_dir, 'foo')
  68.             self.assertRaises(shutil.Error, shutil.move, src_dir, dst)
  69.         finally:
  70.             
  71.             try:
  72.                 os.rmdir(src_dir)
  73.             except:
  74.                 pass
  75.  
  76.  
  77.  
  78.     if hasattr(os, 'symlink'):
  79.         
  80.         def test_dont_copy_file_onto_link_to_itself(self):
  81.             os.mkdir(TESTFN)
  82.             src = os.path.join(TESTFN, 'cheese')
  83.             dst = os.path.join(TESTFN, 'shop')
  84.             
  85.             try:
  86.                 f = open(src, 'w')
  87.                 f.write('cheddar')
  88.                 f.close()
  89.                 os.link(src, dst)
  90.                 self.assertRaises(shutil.Error, shutil.copyfile, src, dst)
  91.                 self.assertEqual(open(src, 'r').read(), 'cheddar')
  92.                 os.remove(dst)
  93.                 os.symlink('cheese', dst)
  94.                 self.assertRaises(shutil.Error, shutil.copyfile, src, dst)
  95.                 self.assertEqual(open(src, 'r').read(), 'cheddar')
  96.                 os.remove(dst)
  97.             finally:
  98.                 
  99.                 try:
  100.                     shutil.rmtree(TESTFN)
  101.                 except OSError:
  102.                     pass
  103.  
  104.  
  105.  
  106.     
  107.  
  108.  
  109. def test_main():
  110.     test_support.run_unittest(TestShutil)
  111.  
  112. if __name__ == '__main__':
  113.     test_main()
  114.  
  115.